<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Boq_model extends CI_Model {
	
	public function __construct()
	{
		parent::__construct();
	}
	
	function get($pay_item = null) 
	{
		$this->db->select()->from('project_boq');
		if ($pay_item != null) 
		{
			$this->db->where('pay_item', $pay_item);
		}
		else 
		{
			$this->db->order_by('pay_item');
		}
 
		$query = $this->db->get();
 
		if ($pay_item != null) 
		{
			return $query->row_array();
		}
		else 
		{
			return $query->result_array();
		}
	}
	
	public function is_boq_exist($pay_item)
	{
		$query = $this->db->get_where('project_boq', array('pay_item' => $pay_item));
		if($query->num_rows() > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function update($pay_item,$data)
	{
		$this->db->where('pay_item', $pay_item);
		$this->db->update('project_boq', $data); 
	}
	
	public function insert($data)
	{
		if($this->db->insert('project_boq', $data))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function delete($pay_item)
	{
		$this->db->delete('project_boq', array('pay_item' => $pay_item) ); 
	}
}